import os
import logging
from datetime import datetime

def setup_logging():
    """
    设置日志系统
    """
    log_dir = 'logs'
    os.makedirs(log_dir, exist_ok=True)
    
    log_filename = f"{log_dir}/forex_fetcher_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
    
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        handlers=[
            logging.FileHandler(log_filename, encoding='utf-8'),
            logging.StreamHandler()
        ]
    )
    
    return logging.getLogger(__name__)

def create_directories():
    """
    创建必要的目录
    """
    directories = ['data', 'logs', 'charts']
    for directory in directories:
        os.makedirs(directory, exist_ok=True)

def format_currency_pair(pair):
    """
    格式化货币对显示
    """
    currency_names = {
        'USD': '美元',
        'CNY': '人民币',
        'EUR': '欧元',
        'GBP': '英镑',
        'JPY': '日元',
        'AUD': '澳元',
        'CHF': '瑞士法郎',
        'CAD': '加元'
    }
    
    if len(pair) == 6:
        base = pair[:3]
        quote = pair[3:]
        base_name = currency_names.get(base, base)
        quote_name = currency_names.get(quote, quote)
        return f"{base_name}/{quote_name}"
    
    return pair
